using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 审批单据控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ApprovalDocumentController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public ApprovalDocumentController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取审批单据列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<ApprovalDocumentDto>>> GetApprovalDocuments([FromQuery] ApprovalDocumentQueryDto query)
        {
            return await _consoleService.GetApprovalDocumentsAsync(query);
        }

        /// <summary>
        /// 获取审批单据详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<ApprovalDocumentDto>> GetApprovalDocument(int id)
        {
            return await _consoleService.GetApprovalDocumentAsync(id);
        }

        /// <summary>
        /// 创建审批单据
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<ApprovalDocumentDto>> CreateApprovalDocument([FromBody] ApprovalDocumentDto dto)
        {
            return await _consoleService.CreateApprovalDocumentAsync(dto);
        }

        /// <summary>
        /// 更新审批单据
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<ApprovalDocumentDto>> UpdateApprovalDocument([FromBody] ApprovalDocumentDto dto)
        {
            return await _consoleService.UpdateApprovalDocumentAsync(dto);
        }

        /// <summary>
        /// 删除审批单据
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteApprovalDocument(int id)
        {
            return await _consoleService.DeleteApprovalDocumentAsync(id);
        }
    }
} 